package com.atguigu.springcloud.alibaba.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.atguigu.springcloud.entities.CommonResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: shikong
 * @Date: 2020/8/11 22:51
 */

@RestController
public class RateLimitcontroller {


    @GetMapping("/byResource")
    @SentinelResource(value = "byResource",blockHandler = "handlerException")
    public CommonResult byResource(){
            return new CommonResult(200,"按照资源名称限流","successfull");
    }


    @GetMapping("/rateLimit/byUrl")
    @SentinelResource(value = "byurl")
    public CommonResult byUrl(){

        return new CommonResult(200,"按照url名称限流","successfull");
    }

    @GetMapping("/rateLimit/customerBlockHandler")
    @SentinelResource(value = "customerBlockHandler",
            blockHandlerClass = CustomerBlockHandler.class,
            blockHandler = "handlerException2")
    public CommonResult customerBlockHandler(){

        return new CommonResult(200,"按照自定义名称限流","successfull");
    }


    public CommonResult handlerException(BlockException BlockException){
        return new CommonResult(444,"按照资源名称限流","error");
    }


}
